package cn.com.guage.guc.callable;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.REUtil;

import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author: LDeng
 * @Date: 2021-09-05 18:58
 */

class MyThread11 implements Runnable{
    @Override
    public void run() {

    }
}

class MyThread22 implements Callable{

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"come in callable");
        return 200;
    }
}

public class Demo11 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
       //Runnable创建线程
        new Thread(new MyThread11(),"AA").start();

       //Callable创建线程
            // 首先创建一个futureTask对象
        FutureTask<Integer> futureTask1 = new FutureTask<Integer>(new MyThread22());
        //lambda
        FutureTask<Integer> futureTask2=new FutureTask<Integer>(()->{
            System.out.println(Thread.currentThread().getName()+"come in callable");
            return 1024;
        });

        new Thread(futureTask1,"AA").start();
        new Thread(futureTask2,"BB").start();
        while (!futureTask2.isDone()){
            System.out.println("waiting 线程AA 计算出结果.........");
            System.out.println("waiting 线程AA 计算出结果.........");

        }
        System.out.println("线程AA计算完成，，计算结果是： "+futureTask1.get());
        System.out.println("线程BB计算完成，，计算结果是： "+futureTask2.get());

    }
}
